//swfupload会自动请求当前页面的父目录，如地址/content/test/2,会请求/content/test,地址/content/test?id=2 会请求/content

function singleUploadFileAutoReturn(upload_url,returnval, buttonId, pro,isImage, isWatermark){
      return singleUploadFile(upload_url, buttonId, pro,function(json){
          if(json && json.success)
          {
              $(returnval).val(json.data);
          }
      }, isImage, false, isWatermark);
}


/*上传文件
upload_url 服务器URL
retunvalue 返回值
pro 进度条控件
*/
function singleUploadFile(upload_url, buttonId, pro,complatecalbak, isImage, isThumbnai, isWatermark) {
    var flashurl=serverUrl.webRoot + 'Content/JavaScript/packages/SWFUpload_v2.2.0.1/Flash/swfupload.swf'; // Relative to this file
    var swfu = new SWFUpload({
        // Backend Settings
        upload_url: upload_url,
        flash_url: flashurl,

        post_params: {
            uploadControlName: 'Filedata',
            ASPSESSID: serverUrl.session_id,
            isImage: isImage,
            isThumbnai: isThumbnai,
            isWatermark: isWatermark
        },
        use_query_string: false,

        // File Upload Settings
        file_queue_limit: "0",
        file_upload_limit: "0",    // Zero means unlimited

        // Button settings
        button_placeholder_id: buttonId,
        button_width: 60,
        button_height: 22,
        button_text: '<span class="button">浏览...</span>',
        button_text_style: '.button { font-size: 12px; text-align:center; }',
        button_image_url: flashurl,  //使flash不自动请求当前目录
        button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
        button_cursor: SWFUpload.CURSOR.HAND,
        button_action: SWFUpload.BUTTON_ACTION.SELECT_FILE,  //设置为单选
        custom_settings: {
            progress: pro
        },

        // Debug Settings
        debug: false,


        // Event Handler Settings - these functions as defined in Handlers.js
        //  The handlers are not part of SWFUpload but are part of my website and control how
        //  my website reacts to the SWFUpload events.
        file_queue_error_handler: fileQueueError,
        file_dialog_complete_handler: fileDialogComplete,
        upload_progress_handler: uploadProgress,
        upload_error_handler: uploadError,
        upload_success_handler: function (file, serverData) {
            try {
                this.setButtonDisabled(false);
                var json = show_txt_msg(serverData);
                if (complatecalbak) complatecalbak(json);
            } catch (ex) {
                this.debug(ex);
            }
        },
        upload_complete_handler: uploadComplete
    });
    return swfu;
}

function fileQueueError(file, errorCode, message) {
    try {
        switch (errorCode) {
            case SWFUpload.errorCode_QUEUE_LIMIT_EXCEEDED:
                message = "选择的文件太多";
            case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
                message = "选择的是空文件";
                break;
            case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
                message = '选择的文件尺寸太大(最大:' + this.settings.file_size_limit + ')';
                break;
            case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
                message = '不是允许上传的文件类型';
                break;
            case 100:

                break;
        }
        $.messager.alert(errorCode, message);
    } catch (ex) {
        this.debug(ex);
    }

}

function fileDialogComplete(numFilesSelected, numFilesQueued) {
    try {
        if (numFilesQueued > 0) {
            this.startUpload();
            this.setButtonDisabled(true);
        }
    } catch (ex) {
        this.debug(ex);
    }
}

function uploadProgress(file, bytesLoaded) {
    try {
        var percent = Math.ceil((bytesLoaded / file.size) * 100);
        var dis = $(this.customSettings.progress);
        if (percent < 100) {
            dis.show();
            dis.val(percent);
        } else {
            dis.hide();
        }
    } catch (ex) {
        this.debug(ex);
    }
}

function uploadComplete(file) {

}

function uploadError(file, errorCode, message) {
    try {


    } catch (ex3) {
        this.debug(ex3);
    }

}